package thirdFragment.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;

import java.util.ArrayList;

import utils.VariousUtils;
import web.activity.WebPage;
import thirdFragment.bean.CollegeBean;
import view.MyImageLoader;


/**
 * Created by Administrator on 2017/2/21.
 */

public class CollegeLvAdapter extends BaseAdapter {
    private ArrayList<CollegeBean.NewsListBean> arrayList;
    private Context context;

    public CollegeLvAdapter(Context context, ArrayList<CollegeBean.NewsListBean> arrayList) {
        this.arrayList = arrayList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        MyRteHolder myRteHolder;
        if ("video".equals(arrayList.get(position).getForm())) {
            if (convertView == null) {
                myRteHolder = new MyRteHolder();
                convertView = LayoutInflater.from(context).inflate(R.layout.college_lv_item, null);
                convertView.setTag(myRteHolder);
            } else {
                myRteHolder = (MyRteHolder) convertView.getTag();
            }
        } else {
            if (convertView == null) {
                myRteHolder = new MyRteHolder();
                convertView = LayoutInflater.from(context).inflate(R.layout.college_lv_item, null);
                myRteHolder.comment = (TextView) convertView.findViewById(R.id.college_item_comment);
                myRteHolder.content = (TextView) convertView.findViewById(R.id.college_item_content);
                myRteHolder.date = (TextView) convertView.findViewById(R.id.college_item_date);
                myRteHolder.imageView = (ImageView) convertView.findViewById(R.id.college_item_ima);
                convertView.setTag(myRteHolder);
            } else {
                myRteHolder = (MyRteHolder) convertView.getTag();
            }
            myRteHolder.comment.setText(arrayList.get(position).getComment());
            myRteHolder.date.setText(arrayList.get(position).getCreate_time());
            MyImageLoader.showImage(arrayList.get(position).getImage(), myRteHolder.imageView);
            myRteHolder.content.setText(arrayList.get(position).getTitle());
        }
        convertView.setOnClickListener(new View.OnClickListener() {
                                           @Override
                                           public void onClick(View v) {
                                               Intent i = new Intent(context, WebPage.class);
                                               i.putExtra("newsid", arrayList.get(position).getId());
                                               i.putExtra("url", VariousUtils.noHttps(arrayList.get(position).getLink()));
                                               context.startActivity(i);
                                           }
                                       }
        );
        return convertView;
    }

    class MyRteHolder {
        //图文板块
        TextView content;
        TextView date;
        TextView comment;
        ImageView imageView;
    }

    class MyVideoHolder {
        //视频板块


    }
}
